package cn.gok.common.enums;

import java.util.Arrays;

/**
 * @author: DxlinY
 * @apiNote: 统一状态码枚举
 * @date: 2020/9/17
 * @time: 16:13
 */
public enum ResultEnum {
    SYSTEM_NORMAL_SUCCESS(20, "操作成功"),
    LOGIN_SUCCESS(21, "登录成功"),

    SYSTEM_UNKNOWN_ERROR(50, "访问出错"),
    LOGIN_FAILED(51, "用户名或密码错误"),
    LOGIN_UNKNOWN_USER(52, "用户不存在"),
    LOGIN_PASSWORD_ERROR(53, "密码错误"),
    SYSTEM_DATA_NOT_FOUND(54, "请求数据未成功获取"),
    SYSTEM_IMAGE_TOO_BIG(55, "上传图片最大为1MB"),
    NOT_PERMISSION(56, "用户无权限访问");
    private int code;
    private String msg;

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ResultEnum get(int code) {
        return Arrays.stream(ResultEnum.values()).filter(resultEnum -> resultEnum.code == code)
                .findAny()
                .orElse(null);
    }

}
